import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15

import "qrc:/Chart/"

Rectangle {
    anchors.fill: parent
    color: "#80000000"
    visible: false

    MouseArea {
        anchors.fill: parent
        onClicked: {
            exit()
        }
    }

    Rectangle {
        anchors.centerIn: parent
        color: "white"
        width: 900
        height: 900
        radius: 20

        Chart {
            id: chartjs_view
            property var data: []

            anchors.fill: parent
            anchors.margins: 20
            z: 10
            chartType: 'scatter'

            chartData: {
                return {
                    "datasets": [{
                            "label": 'Nyquist Chart (点按以刷新图片)',
                            "data": data,
                            "backgroundColor": 'rgba(255, 99, 132, 1)',
                            "pointRadius": 15
                        }]
                }
            }

            chartOptions: {
                return {
                    "title": {
                        "display": true,
                        "text": 'Nyquist Chart'
                    },
                    "scales": {
                        "xAxes": [{
                                "gridLines": {
                                    "zeroLineWidth": 4,
                                    "lineWidth": 3
                                },
                                "scaleLabel": {
                                    "display": true,
                                    "labelString": '实部',
                                    "fontSize"// 设置 x 轴标题为 "实部"
                                    : 30 // 设置标题的字体大小
                                },
                                "axisLine": {
                                    "borderWidth": 10,
                                    "borderColor"// 这里设置坐标轴线（轴线本身）的线宽
                                    : 'black' // 这里设置坐标轴线的颜色
                                }
                            }],
                        "yAxes": [{
                                "gridLines": {
                                    "zeroLineWidth": 4,
                                    "lineWidth": 3
                                },
                                "scaleLabel": {
                                    "display": true,
                                    "labelString": '-虚部',
                                    "fontSize"// 设置 x 轴标题为 "实部"
                                    : 30 // 设置标题的字体大小
                                },
                                "axisLine": {
                                    "display": true,
                                    "lineWidth"// 显示坐标轴线
                                    : 10,
                                    "color"// 设置坐标轴线的宽度
                                    : 'black' // 设置坐标轴线的颜色
                                }
                            }]
                    }
                }
            }
        }
    }

    function show(result) {
        chartjs_view.data = []

        result.points.forEach(function (item) {
            chartjs_view.data.push({
                                "x": item.real,
                                "y": -item.imag
                            })
        })
        visible = true
    }

    function exit() {
        visible = false
    }
}
